//
//  LGTeamMemberCell.m
//  BreathTrainingTool
//
//  Created by 1234 on 2024/7/11.
//  团队成员

#import "LGTeamMemberCell.h"

@interface LGTeamMemberCell()
/**   */
@property (nonatomic , strong)UIImageView *headPic;
/**   */
@property (nonatomic , strong)UILabel *nameLabel;
/**   */
@property (nonatomic , strong)UILabel *tipLabel;
/**   */
@property (nonatomic , strong)UILabel *postTitle;
/**   */
@property (nonatomic , strong)UIButton *removeBtn;

@end

@implementation LGTeamMemberCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.type = LGPositionTypeSingle;
        [self createSubView];
    }
    return  self;
}

-(void)setCanRemove:(BOOL)canRemove{
    _canRemove = canRemove;
    self.removeBtn.hidden = !canRemove;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    [super setDataDic:dataDic];
    [self.headPic sd_setImageWithURL:[NSURL URLWithString:LGNSString(dataDic[@"avatar"])] placeholderImage:[UIImage imageNamed:@"医生头像"]];
    self.nameLabel.text = LGNSString(dataDic[@"realName"]);
    self.postTitle.text = LGNSString(dataDic[@"roleName"]);
    self.tipLabel.hidden = [LGNSString(dataDic[@"manager"]) isEqualToString:@"1"]?NO:YES;
    self.removeBtn.hidden = [LGNSString(dataDic[@"manager"]) isEqualToString:@"1"]?YES:self.removeBtn.hidden;
}

-(void)removeBtnAction{
    if (self.delegate && [self.delegate respondsToSelector:@selector(removeMember:)]) {
        [self.delegate removeMember:LGNSString(self.dataDic[@"id"])];
    }
}

#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    [self.baseView addSubview:self.headPic];
    [self.baseView addSubview:self.nameLabel];
    [self.baseView addSubview:self.tipLabel];
    [self.baseView addSubview:self.postTitle];
    [self.baseView addSubview:self.removeBtn];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.baseView).offset(viewPix(16));
        make.left.equalTo(self.headPic.mas_right).offset(viewPix(12));
    }];
    [self.tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.mas_right).offset(viewPix(10));
        make.centerY.equalTo(self.nameLabel);
        make.width.equalTo(@(viewPix(50)));
        make.height.equalTo(@(viewPix(20)));
    }];
    [self.postTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.nameLabel.mas_bottom).offset(viewPix(5));
        make.left.equalTo(self.nameLabel);
        make.bottom.equalTo(self.baseView).offset(-viewPix(16));
    }];
    [self.removeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.right.bottom.equalTo(self.baseView);
        make.width.equalTo(@(viewPix(60)));
    }];
}
-(UIImageView *)headPic{
    if(!_headPic){
        _headPic = [[UIImageView alloc]initWithFrame:CGRectMake(viewPix(16), viewPix(16), viewPix(42), viewPix(42))];
        _headPic.cornerRidus = viewPix(21);
    }
    return _headPic;
}

-(UILabel *)nameLabel{
    if(!_nameLabel){
        _nameLabel = [UILabel lableWithText:@"" colorString:@"#2B2A37" textFont:LGFontWeight(16, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _nameLabel;
}

-(UILabel *)postTitle{
    if(!_postTitle){
        _postTitle = [UILabel lableWithText:@"" colorString:@"#968F8F" textFont:LGFont(13) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _postTitle;
}

-(UILabel *)tipLabel{
    if(!_tipLabel){
        _tipLabel = [UILabel lableWithText:@"队长" colorString:@"#E29E00" textFont:LGFont(14) textAlignment:NSTextAlignmentCenter lines:1];
        [_tipLabel addBorder:@"#E29E00" lineWidth:1 cornerRidus:viewPix(10)];
    }
    return _tipLabel;
}

-(UIButton *)removeBtn{
    if(!_removeBtn){
        _removeBtn = [UIButton buttonWithTitle:@"移除" titleFont:LGFont(14) textColor:kThemeColor frame:CGRectZero];
        [_removeBtn addTarget:self action:@selector(removeBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _removeBtn;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
